package com.fs.service.impl;

import com.fs.dao.ClassDao;
import com.fs.pojo.Class;
import com.fs.utils.BeanFactories;


import com.alibaba.fastjson.JSONArray;
import com.fs.dao.ClassStudentDao;
import com.fs.pojo.ClassStudent;

import com.fs.service.ClassService;

import java.util.List;

public class ClassServiceImpl implements ClassService {


    private ClassDao classDao = BeanFactories.getBean(ClassDao.class);

    @Override
    public Class createClass(Class cla) {

        String id = classDao.insertReturnId(cla);
        if(id!=null){
            Class aClass = classDao.queryById(id);
            return aClass;
        }
        return null;


    }


    @Override
    public boolean delClass(String classId) {
        return classDao.deleteById(classId)>0?true:false;
    }

    @Override
    public boolean updateClass(Class cla) {
        return classDao.update(cla)>0?true:false;
    }


    @Override
    public int deleteStudentInClass(String classId, JSONArray idArr) {
        ClassStudentDao classStudentDao = BeanFactories.getBean(ClassStudentDao.class);
        int  result = 1;
        for (int i = 0; i < idArr.size(); i++) {
            int oneResult =classStudentDao.deleteByClassIdAndStudenID(classId,(String)idArr.get(i));
            if (oneResult<0){
                System.out.println(result);
                result =0;
            }
        }
        return result;
    }

    @Override
    public Class queryClassByCourseIdAndstudentId(String studentId) {

        return classDao.queryClassByCourseIdAndstudentId(studentId);
    }

}
